#include "head.h"
/* Usage: */

Queue_t* createQueue(){
    Queue_t *q = (Queue_t*)calloc(1, sizeof(Queue_t));
    if(!q){
        perror("创建队列失败！\n");
        return NULL;
    }
    return q;
}

bool destroyQueue(Queue_t *q){
    if(!q) return false;
    while(q->head){
        Node_t *t = q->head;
        q->head = q->head->next;
        free(t);
    }
    free(q);
    return true;
}

bool isEmpty(Queue_t *q){
    return q->size==0;
}

bool push(Queue_t *q, ELEMENTYPE data){
    Node_t *new_node = (Node_t*)calloc(1, sizeof(Node_t));
    if(!new_node){
        return false;
    }
    new_node->data = data;
    if(q->head==NULL){
        q->head = q->tail = new_node;
    } else {
        q->tail->next = new_node;
        q->tail = new_node;
    }
    q->size++;
    return true;
}

ELEMENTYPE pop(Queue_t *q){
    Node_t *t = q->head;
    ELEMENTYPE data = t->data;
    printf("user = %s\n", data->user_name);
    q->head = q->head->next;
    q->size--;
    free(t);
    return data;
}
